package com.atlin.nrpc.core.util;

import cn.hutool.core.util.StrUtil;
import cn.hutool.setting.dialect.Props;
import cn.hutool.setting.yaml.YamlUtil;

/**
 * 配置工具类
 */
public class ConfigUtils {


    /**
     * 加载配置对象
     *
     * @param tClazz
     * @param prefix
     * @param <T>
     * @return
     */
    public static <T> T loadConfig(Class<T> tClazz, String prefix) {
        return loadConfig(tClazz, prefix, "");
    }


    /**
     * 加载配置对象，区分环境
     *
     * @param tClazz
     * @param prefix
     * @param environment
     * @param <T>
     * @return
     */
    public static <T> T loadConfig(Class<T> tClazz, String prefix, String environment) {
        StringBuilder configFileBuild = new StringBuilder("application");
        if (StrUtil.isNotBlank(environment)) {
            configFileBuild.append("-").append(environment);
        }
        configFileBuild.append(".yml");
        Props props = new Props(configFileBuild.toString());
        return props.toBean(tClazz, prefix);
//        return YamlUtil.loadByPath(configFileBuild.toString(),tClazz);


    }
}
